<?php
/**
 * Created by PhpStorm.
 * User: Candice俊俊
 * Date: 2016/7/22
 * Time: 9:25
 */

namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller
{
    //登陆
    public function login(){
        $this->display();//转移，没有处理任何数据

    }

    public function dologin(){
        $condition=array(
            'adminname'=>$_POST['adminname'],
            'password'=>md5(I('post.password'))//I方法更加安全
        );
        $adminModel=M('Admin');
        $admin=$adminModel->where($condition)->find();
        if($admin){
            //是合法用户
            session('admin',$admin);
            $this->redirect('Index/users');
        }else{
            //是非法用户
            $this ->error('用户名或口令错误');
        }
    }
    public function logout(){
        session('admin',null);
        //exit();
        $this->redirect('login');
    }
}